local saojian = fk.CreateSkill {
    name = "gai__saojian",
  }
  
  Fk:loadTranslationTable{
    ["gai__saojian"] = "埽奸",
    [":gai__saojian"] = "出牌阶段限一次，你可以观看一名其他角色的手牌并选择其中一张令除其外的角色观看，然后其重复弃置一张手牌（至多五次），"..
    "直至其弃置了你选择的牌。然后若其手牌数大于你，你失去1点体力；若其因此失去最后一张手牌，此技能视为未发动过。",
  
    ["#saojian"] = "埽奸：观看一名其他角色的手牌，令其弃置手牌直到弃到你所选的牌",
    ["#SaoJianReveal"] = "%from选择",
    ["#saojian-discard"] = "埽奸：请弃置一张手牌，直到你弃置到“埽奸”选择的牌（剩余%arg次）",
  }
  
  saojian:addEffect("active", {
    anim_type = "control",
    prompt = "#saojian",
    card_num = 0,
    target_num = 1,
    mute = true,
    can_use = function(self, player)
      return player:usedSkillTimes(saojian.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected)
      return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      room:notifySkillInvoked(player, saojian.name)
      player:broadcastSkillInvoke(saojian.name, math.random(1, 2))
      local target = effect.tos[1]
      if target:isKongcheng() then return end
  
      local card = room:askToChooseCard(player, {
        target = target,
        flag = { card_data = {{ target.general, target:getCardIds("h") }} },
        skill_name = saojian.name,
      })
  
      local toViewPlayers = table.filter(room.alive_players, function(p) return p ~= target end)
      if #toViewPlayers > 0 then
        for _, p in ipairs(toViewPlayers) do
          p:doNotify("ShowCard",
          {
            from = player.id,
            cards = {card},
          })
        end
        room:sendFootnote({card}, {
          type = "#SaoJianReveal",
          from = player.id,
        })
      end
  
      -- 记录目标初始手牌数
      local initialHandcardNum = target:getHandcardNum()
      local resetSkill = false
  
      for i = 1, 5 do
        local ids = room:askToDiscard(target, {
          min_num = 1,
          max_num = 1,
          include_equip = false,
          skill_name = saojian.name,
          cancelable = false,
          prompt = "#saojian-discard:::" .. 6 - i,
        })
        
        if #ids == 0 or target.dead then
          break
        end
        
        -- 检查是否弃置了选择的牌
        if ids[1] == card then
          -- 如果弃置后手牌数为0，则标记重置技能
          if target:getHandcardNum() == 0 then
            resetSkill = true
          end
          break
        end
        
        if i == 5 then 
          player:broadcastSkillInvoke(saojian.name, 4) 
        end
      end
  
      if player:isAlive() and target:getHandcardNum() > player:getHandcardNum() then
        player:broadcastSkillInvoke(saojian.name, 3)
        room:loseHp(player, 1, saojian.name)
      end
  
      -- 如果目标因此失去最后一张手牌，重置技能使用次数
      if resetSkill then
        player:setSkillUseHistory(saojian.name, 0, Player.HistoryPhase)
      end
    end,
  })
  
  return saojian